﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LeagueOfRila.Model;
using LeagueOfRila.Controller;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace LeagueOfRila.View
{
    abstract public class BaseView:Microsoft.Xna.Framework.Game
    {
        public BaseController controller;
        public virtual BaseModel model{get;set;}

        public GraphicsDeviceManager graphics;
        public SpriteBatch spriteBatch;
        protected SpriteFont font;

        public BaseView()
        {
            graphics = new GraphicsDeviceManager(this);
            
           Content.RootDirectory = "Content";
           
            
        }
        protected override void LoadContent()
        {
            this.spriteBatch = new SpriteBatch(GraphicsDevice);
            this.font = Content.Load<SpriteFont>("SpriteFont1");
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
     
            this.controller.Update(gameTime);

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {

            base.Draw(gameTime);
        }

        protected void DrawImage(Texture2D image, Rectangle position)
        {
            this.spriteBatch.Begin();   
            this.spriteBatch.Draw(image, position, Color.White);
            this.spriteBatch.End();
        }
        protected void DrawBackgroundImage(Texture2D image)
        {

            DrawImage(image, new Rectangle(0, 0, this.GraphicsDevice.Viewport.Width, this.GraphicsDevice.Viewport.Height));
        }
        protected void DrawBackgroundColor(int r, int g, int b)
        {
            spriteBatch.Begin();
            GraphicsDevice.Clear(new Color(r, g, b));
            spriteBatch.End();
        }
        public void DrawFont(string texte, Vector2 position, Color color )
        {      
            spriteBatch.Begin();
            spriteBatch.DrawString(this.font, texte, position, color);
            spriteBatch.End();
        }
        protected void DrawRectangle(Rectangle rectangle, Color color)
        {
            this.spriteBatch.Begin();
            Texture2D t2D = new Texture2D(this.GraphicsDevice, 1, 1);
            t2D.SetData(new[]{Color.White}); 
            this.spriteBatch.Draw(t2D, rectangle, color);
            this.spriteBatch.End();
        }

        public void DrawImage(Texture2D image, Rectangle position, Rectangle destination, Color? color = null)
        {
            Color innerColor = Color.White;
            if (color != null)
                innerColor = (Color)color * 0.5f;

            this.spriteBatch.Begin();
            this.spriteBatch.Draw(image, position, destination, innerColor);
            this.spriteBatch.End();
        }
    }
}
